package dimension.starry.loot;

import dimension.starry.utils.RandomUtil;
import net.minecraft.item.Item;
import net.minecraft.item.Items;

import java.util.HashMap;
import java.util.Map;

public class NormalLoots {

    private static final Map<Item, Integer> LOOT_WEIGHT_MAP = new HashMap<>() {{
        put(Items.TROPICAL_FISH, 100);
        put(Items.AIR, 60000);
        put(Items.APPLE, 1000);
        put(Items.ARROW, 100);
        put(Items.BAMBOO, 100);
        put(Items.BAKED_POTATO, 100);
        put(Items.BEEF, 100);
        put(Items.BLUE_ICE, 100);
        put(Items.BONE, 100);
        put(Items.BOOK, 100);
        put(Items.BOW, 100);
        put(Items.BOWL, 1000);
        put(Items.BREAD, 100);
        put(Items.BRICK, 100);
        put(Items.BUCKET, 50);
        put(Items.CAKE, 100);
        put(Items.CHICKEN, 100);
        put(Items.CLAY_BALL, 100);
        put(Items.CLOCK, 50);
        put(Items.COAL, 50);
        put(Items.COBBLESTONE, 100);
        put(Items.COMPASS, 50);
        put(Items.COOKED_BEEF, 100);
        put(Items.COOKIE, 100);
        put(Items.COOKED_CHICKEN, 100);
        put(Items.COOKED_COD, 100);
        put(Items.COOKED_MUTTON, 100);
        put(Items.COOKED_PORKCHOP, 100);
        put(Items.COOKED_RABBIT, 100);
        put(Items.COOKED_SALMON, 100);
        put(Items.CRAFTING_TABLE, 100);
        put(Items.CROSSBOW, 100);
        put(Items.DIRT, 1000);
        put(Items.EGG, 100);
        put(Items.ENCHANTED_GOLDEN_APPLE, 1);
        put(Items.ENDER_EYE, 30);
        put(Items.FLINT, 1000);
        put(Items.FEATHER, 2000);
        put(Items.FISHING_ROD, 100);
        put(Items.FLOWER_POT, 100);
        put(Items.FURNACE, 100);
        put(Items.FURNACE_MINECART, 100);
        put(Items.GLASS_BOTTLE, 100);
        put(Items.HONEY_BOTTLE, 100);
        put(Items.ICE, 100);
        put(Items.ITEM_FRAME, 100);
        put(Items.LADDER, 100);
        put(Items.MAP, 100);
        put(Items.MELON, 100);
        put(Items.MELON_SEEDS, 100);
        put(Items.MINECART, 100);
        put(Items.MUSIC_DISC_5, 50);
        put(Items.MUSIC_DISC_11, 50);
        put(Items.MUSIC_DISC_13, 50);
        put(Items.MUSIC_DISC_BLOCKS, 50);
        put(Items.MUSIC_DISC_CAT, 50);
        put(Items.MUSIC_DISC_CHIRP, 50);
        put(Items.MUSIC_DISC_FAR, 50);
        put(Items.MUSIC_DISC_MALL, 50);
        put(Items.MUSIC_DISC_MELLOHI, 50);
        put(Items.MUSIC_DISC_OTHERSIDE, 50);
        put(Items.MUSIC_DISC_PIGSTEP, 50);
        put(Items.MUSIC_DISC_RELIC, 50);
        put(Items.MUSIC_DISC_STAL, 50);
        put(Items.MUSIC_DISC_STRAD, 50);
        put(Items.MUSIC_DISC_WAIT, 50);
        put(Items.MUSIC_DISC_WARD, 50);
        put(Items.NAME_TAG, 10);
        put(Items.PAINTING, 100);
        put(Items.POTATO, 100);
        put(Items.PORKCHOP, 100);
        put(Items.RABBIT, 100);
        put(Items.RAIL, 100);
        put(Items.SAND, 100);
        put(Items.SHIELD, 50);
        put(Items.SHEARS, 50);
        put(Items.SLIME_BALL, 50);
        put(Items.SNOWBALL, 100);
        put(Items.STICK, 2000);
        put(Items.TORCH, 1000);
        put(Items.WHEAT, 1000);
        put(Items.WHEAT_SEEDS, 1000);
    }};

    public static Item getRandomItem() {
        int totalWeight = LOOT_WEIGHT_MAP.values().stream().mapToInt(i -> i).sum();
        int random = RandomUtil.randomInt(1, totalWeight + 1), current = 0;
        for (Map.Entry<Item, Integer> entry : LOOT_WEIGHT_MAP.entrySet()) {
            if (random > current && random <= current + entry.getValue()) {
                return entry.getKey();
            }
            current += entry.getValue();
        }
        throw new RuntimeException(String.format("calculate error, weight not in range: total=%d random=%d current=%d",
            totalWeight,
            random,
            current
        ));
    }

}
